<?php
namespace Modules\Backend\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class AdminRegisterRequest extends FormRequest
{

    private  $table="admins";

    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        switch (strtolower($this->method())){
            case "post":
                return [
                    'user_name' => ['required', 'min:6', 'max:20', 'unique:'.$this->table],
                    'email' => ['required', 'email', 'max:255', 'unique:'.$this->table],
                    'password' => ['required',  'min:8', 'confirmed'],
                ];
            default:
                return [];
        }
    }

    public function messages()
    {
        return [
            'user_name.required' => '管理员用户名必须填写',
            'user_name.min' => '管理员用户名长度为6到30位',
            'user_name.max' => '管理员用户名长度为6到30位',
            'user_name.unique' => '管理员用户名已经存在',
            'email.required' => '管理员邮箱必须填写',
            'email.email' => '管理员邮箱格式不正确',
            'email.max' => '管理员邮箱长度最长255位',
            'email.unique' => '管理员邮箱已经存在',
            'password.required' => '管理员密码必须填写',
            'password.min' => '管理员密码最短8位',
            'password.confirmed' => '两次密码不一致',
        ];
    }
}
